
根据项目结构和规范，我生成了针对 `AudioDecoderFilter::ProcessData` 函数的单元测试代码。以下是完整的测试文件：

```cpp
/*
 * Copyright (c) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "av_trans_audio_decoder_filter.h"
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <memory>
#include <mutex>
#include <queue>
#include <string>
#include <vector>
#include <thread>
#include <condition_variable>
#include <atomic>
#include <map>

using namespace testing;
using namespace testing::ext;

namespace OHOS {
namespace DistributedHardware {
namespace Pipeline {

class MockAudioDecoderFilter : public AudioDecoderFilter {
public:
    MockAudioDecoderFilter(std::string name, FilterType type) : AudioDecoderFilter(name, type) {}
    ~MockAudioDecoderFilter() = default;

    // 暴露私有成员用于测试
    using AudioDecoderFilter::ProcessData;
    
    // 暴露私有成员变量用于测试
    std::atomic<bool>& GetDecoderRunning() { return isDecoderRunning_; }
    OH_AVCodec*& GetAudioDecoder() { return audioDecoder_; }
    std::map<uint32_t, int64_t>& GetPtsMap() { return ptsMap_; }
    uint64_t& GetFrameInIndex() { return frameInIndex_; }
    uint64_t& GetFrameOutIndex() { return frameOutIndex_; }
};

class AudioDecoderFilterTest : public testing::Test {
public:
    static void SetUpTestCase(void);
    static void TearDownTestCase(void);
    void SetUp();
    void TearDown();

    std::shared_ptr<MockAudioDecoderFilter> filter_;
};

void AudioDecoderFilterTest::SetUpTestCase(void)
{
    // 所有测试开始前执行一次
}

void AudioDecoderFilterTest::TearDownTestCase(void)
{
    // 所有测试结束后执行一次
}

void AudioDecoderFilterTest::SetUp()
{
    filter_ = std::make_shared<MockAudioDecoderFilter>("TestAudioDecoder", FilterType::FILTERTYPE_ADEC);
    GTEST_LOG_(INFO) << "SetUp";
}

void AudioDecoderFilterTest::TearDown()
{
    filter_ = nullptr;
    GTEST_LOG_(INFO) << "TearDown";
}

/**
 * @tc.number: AudioDecoderFilter_ProcessData_001
 * @tc.name: AudioDecoderFilter::ProcessData
 * @tc.desc: Verify normal data processing with valid inputs
 */
HWTEST_F(AudioDecoderFilterTest, AudioDecoderFilter_ProcessData_001, TestSize.Level1)
{
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-begin AudioDecoderFilter_ProcessData_001";
    
    ASSERT_NE(filter_, nullptr);
    
    // 设置解码器运行状态
    filter_->GetDecoderRunning().store(true);
    
    // 模拟创建解码器（不为空即可）
    filter_->GetAudioDecoder() = reinterpret_cast<OH_AVCodec*>(0x12345678);
    
    // 准备有效的 audioData
    auto audioData = std::make_shared<Media::AVBuffer>();
    audioData->memory_ = std::make_shared<Media::AVSharedMemory>(1024, Media::AVSharedMemory::FLAGS_READ_WRITE);
    audioData->meta_ = std::make_shared<Media::Meta>();
    audioData->pts_ = 1000;
    
    // 准备有效的 codecMem
    OH_AVBuffer codecMem;
    codecMem.buffer_ = new OH_AVCodecBuffer();
    codecMem.buffer_->memory_ = std::make_shared<Media::AVSharedMemory>(1024, Media::AVSharedMemory::FLAGS_READ_WRITE);
    codecMem.buffer_->meta_ = std::make_shared<Media::Meta>();
    
    // 执行测试
    Status result = filter_->ProcessData(audioData, 1, &codecMem);
    
    // 验证结果
    EXPECT_EQ(result, Status::OK);
    EXPECT_EQ(filter_->GetFrameInIndex(), 1);
    EXPECT_EQ(filter_->GetPtsMap()[0], 1000);
    
    // 清理
    delete codecMem.buffer_;
    
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-end AudioDecoderFilter_ProcessData_001";
}

/**
 * @tc.number: AudioDecoderFilter_ProcessData_002
 * @tc.name: AudioDecoderFilter::ProcessData - Decoder not running
 * @tc.desc: Verify error handling when decoder is not running
 */
HWTEST_F(AudioDecoderFilterTest, AudioDecoderFilter_ProcessData_002, TestSize.Level1)
{
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-begin AudioDecoderFilter_ProcessData_002";
    
    ASSERT_NE(filter_, nullptr);
    
    // 设置解码器为未运行状态
    filter_->GetDecoderRunning().store(false);
    
    // 准备有效的输入参数
    auto audioData = std::make_shared<Media::AVBuffer>();
    audioData->memory_ = std::make_shared<Media::AVSharedMemory>(1024, Media::AVSharedMemory::FLAGS_READ_WRITE);
    audioData->meta_ = std::make_shared<Media::Meta>();
    
    OH_AVBuffer codecMem;
    codecMem.buffer_ = new OH_AVCodecBuffer();
    codecMem.buffer_->memory_ = std::make_shared<Media::AVSharedMemory>(1024, Media::AVSharedMemory::FLAGS_READ_WRITE);
    codecMem.buffer_->meta_ = std::make_shared<Media::Meta>();
    
    // 执行测试
    Status result = filter_->ProcessData(audioData, 1, &codecMem);
    
    // 验证结果
    EXPECT_EQ(result, Status::ERROR_INVALID_OPERATION);
    
    // 清理
    delete codecMem.buffer_;
    
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-end AudioDecoderFilter_ProcessData_002";
}

/**
 * @tc.number: AudioDecoderFilter_ProcessData_003
 * @tc.name: AudioDecoderFilter::ProcessData - AudioDecoder is null
 * @tc.desc: Verify error handling when audio decoder is null
 */
HWTEST_F(AudioDecoderFilterTest, AudioDecoderFilter_ProcessData_003, TestSize.Level1)
{
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-begin AudioDecoderFilter_ProcessData_003";
    
    ASSERT_NE(filter_, nullptr);
    
    // 设置解码器运行但解码器对象为空
    filter_->GetDecoderRunning().store(true);
    filter_->GetAudioDecoder() = nullptr;
    
    // 准备有效的输入参数
    auto audioData = std::make_shared<Media::AVBuffer>();
    audioData->memory_ = std::make_shared<Media::AVSharedMemory>(1024, Media::AVSharedMemory::FLAGS_READ_WRITE);
    audioData->meta_ = std::make_shared<Media::Meta>();
    
    OH_AVBuffer codecMem;
    codecMem.buffer_ = new OH_AVCodecBuffer();
    codecMem.buffer_->memory_ = std::make_shared<Media::AVSharedMemory>(1024, Media::AVSharedMemory::FLAGS_READ_WRITE);
    codecMem.buffer_->meta_ = std::make_shared<Media::Meta>();
    
    // 执行测试
    Status result = filter_->ProcessData(audioData, 1, &codecMem);
    
    // 验证结果
    EXPECT_EQ(result, Status::ERROR_INVALID_OPERATION);
    
    // 清理
    delete codecMem.buffer_;
    
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-end AudioDecoderFilter_ProcessData_003";
}

/**
 * @tc.number: AudioDecoderFilter_ProcessData_004
 * @tc.name: AudioDecoderFilter::ProcessData - Null audioData
 * @tc.desc: Verify error handling when audioData is null
 */
HWTEST_F(AudioDecoderFilterTest, AudioDecoderFilter_ProcessData_004, TestSize.Level1)
{
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-begin AudioDecoderFilter_ProcessData_004";
    
    ASSERT_NE(filter_, nullptr);
    
    // 设置解码器运行状态
    filter_->GetDecoderRunning().store(true);
    filter_->GetAudioDecoder() = reinterpret_cast<OH_AVCodec*>(0x12345678);
    
    // 准备有效的 codecMem
    OH_AVBuffer codecMem;
    codecMem.buffer_ = new OH_AVCodecBuffer();
    codecMem.buffer_->memory_ = std::make_shared<Media::AVSharedMemory>(1024, Media::AVSharedMemory::FLAGS_READ_WRITE);
    codecMem.buffer_->meta_ = std::make_shared<Media::Meta>();
    
    // 执行测试 (audioData 为 nullptr)
    Status result = filter_->ProcessData(nullptr, 1, &codecMem);
    
    // 验证结果
    EXPECT_EQ(result, Status::ERROR_NULL_POINTER);
    
    // 清理
    delete codecMem.buffer_;
    
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-end AudioDecoderFilter_ProcessData_004";
}

/**
 * @tc.number: AudioDecoderFilter_ProcessData_005
 * @tc.name: AudioDecoderFilter::ProcessData - Null audioData memory
 * @tc.desc: Verify error handling when audioData memory is null
 */
HWTEST_F(AudioDecoderFilterTest, AudioDecoderFilter_ProcessData_005, TestSize.Level1)
{
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-begin AudioDecoderFilter_ProcessData_005";
    
    ASSERT_NE(filter_, nullptr);
    
    // 设置解码器运行状态
    filter_->GetDecoderRunning().store(true);
    filter_->GetAudioDecoder() = reinterpret_cast<OH_AVCodec*>(0x12345678);
    
    // 准备 audioData 但 memory 为空
    auto audioData = std::make_shared<Media::AVBuffer>();
    audioData->memory_ = nullptr;
    audioData->meta_ = std::make_shared<Media::Meta>();
    
    OH_AVBuffer codecMem;
    codecMem.buffer_ = new OH_AVCodecBuffer();
    codecMem.buffer_->memory_ = std::make_shared<Media::AVSharedMemory>(1024, Media::AVSharedMemory::FLAGS_READ_WRITE);
    codecMem.buffer_->meta_ = std::make_shared<Media::Meta>();
    
    // 执行测试
    Status result = filter_->ProcessData(audioData, 1, &codecMem);
    
    // 验证结果
    EXPECT_EQ(result, Status::ERROR_NULL_POINTER);
    
    // 清理
    delete codecMem.buffer_;
    
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-end AudioDecoderFilter_ProcessData_005";
}

/**
 * @tc.number: AudioDecoderFilter_ProcessData_006
 * @tc.name: AudioDecoderFilter::ProcessData - Null audioData meta
 * @tc.desc: Verify error handling when audioData meta is null
 */
HWTEST_F(AudioDecoderFilterTest, AudioDecoderFilter_ProcessData_006, TestSize.Level1)
{
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-begin AudioDecoderFilter_ProcessData_006";
    
    ASSERT_NE(filter_, nullptr);
    
    // 设置解码器运行状态
    filter_->GetDecoderRunning().store(true);
    filter_->GetAudioDecoder() = reinterpret_cast<OH_AVCodec*>(0x12345678);
    
    // 准备 audioData 但 meta 为空
    auto audioData = std::make_shared<Media::AVBuffer>();
    audioData->memory_ = std::make_shared<Media::AVSharedMemory>(1024, Media::AVSharedMemory::FLAGS_READ_WRITE);
    audioData->meta_ = nullptr;
    
    OH_AVBuffer codecMem;
    codecMem.buffer_ = new OH_AVCodecBuffer();
    codecMem.buffer_->memory_ = std::make_shared<Media::AVSharedMemory>(1024, Media::AVSharedMemory::FLAGS_READ_WRITE);
    codecMem.buffer_->meta_ = std::make_shared<Media::Meta>();
    
    // 执行测试
    Status result = filter_->ProcessData(audioData, 1, &codecMem);
    
    // 验证结果
    EXPECT_EQ(result, Status::ERROR_NULL_POINTER);
    
    // 清理
    delete codecMem.buffer_;
    
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-end AudioDecoderFilter_ProcessData_006";
}

/**
 * @tc.number: AudioDecoderFilter_ProcessData_007
 * @tc.name: AudioDecoderFilter::ProcessData - Null codecMem
 * @tc.desc: Verify error handling when codecMem is null
 */
HWTEST_F(AudioDecoderFilterTest, AudioDecoderFilter_ProcessData_007, TestSize.Level1)
{
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-begin AudioDecoderFilter_ProcessData_007";
    
    ASSERT_NE(filter_, nullptr);
    
    // 设置解码器运行状态
    filter_->GetDecoderRunning().store(true);
    filter_->GetAudioDecoder() = reinterpret_cast<OH_AVCodec*>(0x12345678);
    
    // 准备有效的 audioData
    auto audioData = std::make_shared<Media::AVBuffer>();
    audioData->memory_ = std::make_shared<Media::AVSharedMemory>(1024, Media::AVSharedMemory::FLAGS_READ_WRITE);
    audioData->meta_ = std::make_shared<Media::Meta>();
    
    // 执行测试 (codecMem 为 nullptr)
    Status result = filter_->ProcessData(audioData, 1, nullptr);
    
    // 验证结果
    EXPECT_EQ(result, Status::ERROR_NULL_POINTER);
    
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-end AudioDecoderFilter_ProcessData_007";
}

/**
 * @tc.number: AudioDecoderFilter_ProcessData_008
 * @tc.name: AudioDecoderFilter::ProcessData - Null codecMem buffer
 * @tc.desc: Verify error handling when codecMem buffer is null
 */
HWTEST_F(AudioDecoderFilterTest, AudioDecoderFilter_ProcessData_008, TestSize.Level1)
{
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-begin AudioDecoderFilter_ProcessData_008";
    
    ASSERT_NE(filter_, nullptr);
    
    // 设置解码器运行状态
    filter_->GetDecoderRunning().store(true);
    filter_->GetAudioDecoder() = reinterpret_cast<OH_AVCodec*>(0x12345678);
    
    // 准备有效的 audioData
    auto audioData = std::make_shared<Media::AVBuffer>();
    audioData->memory_ = std::make_shared<Media::AVSharedMemory>(1024, Media::AVSharedMemory::FLAGS_READ_WRITE);
    audioData->meta_ = std::make_shared<Media::Meta>();
    
    // 准备 codecMem 但 buffer 为空
    OH_AVBuffer codecMem;
    codecMem.buffer_ = nullptr;
    
    // 执行测试
    Status result = filter_->ProcessData(audioData, 1, &codecMem);
    
    // 验证结果
    EXPECT_EQ(result, Status::ERROR_NULL_POINTER);
    
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-end AudioDecoderFilter_ProcessData_008";
}

/**
 * @tc.number: AudioDecoderFilter_ProcessData_009
 * @tc.name: AudioDecoderFilter::ProcessData - Null codecMem memory
 * @tc.desc: Verify error handling when codecMem memory is null
 */
HWTEST_F(AudioDecoderFilterTest, AudioDecoderFilter_ProcessData_009, TestSize.Level1)
{
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-begin AudioDecoderFilter_ProcessData_009";
    
    ASSERT_NE(filter_, nullptr);
    
    // 设置解码器运行状态
    filter_->GetDecoderRunning().store(true);
    filter_->GetAudioDecoder() = reinterpret_cast<OH_AVCodec*>(0x12345678);
    
    // 准备有效的 audioData
    auto audioData = std::make_shared<Media::AVBuffer>();
    audioData->memory_ = std::make_shared<Media::AVSharedMemory>(1024, Media::AVSharedMemory::FLAGS_READ_WRITE);
    audioData->meta_ = std::make_shared<Media::Meta>();
    
    // 准备 codecMem 但 memory 为空
    OH_AVBuffer codecMem;
    codecMem.buffer_ = new OH_AVCodecBuffer();
    codecMem.buffer_->memory_ = nullptr;
    codecMem.buffer_->meta_ = std::make_shared<Media::Meta>();
    
    // 执行测试
    Status result = filter_->ProcessData(audioData, 1, &codecMem);
    
    // 验证结果
    EXPECT_EQ(result, Status::ERROR_NULL_POINTER);
    
    // 清理
    delete codecMem.buffer_;
    
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-end AudioDecoderFilter_ProcessData_009";
}

/**
 * @tc.number: AudioDecoderFilter_ProcessData_010
 * @tc.name: AudioDecoderFilter::ProcessData - Null codecMem meta
 * @tc.desc: Verify error handling when codecMem meta is null
 */
HWTEST_F(AudioDecoderFilterTest, AudioDecoderFilter_ProcessData_010, TestSize.Level1)
{
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-begin AudioDecoderFilter_ProcessData_010";
    
    ASSERT_NE(filter_, nullptr);
    
    // 设置解码器运行状态
    filter_->GetDecoderRunning().store(true);
    filter_->GetAudioDecoder() = reinterpret_cast<OH_AVCodec*>(0x12345678);
    
    // 准备有效的 audioData
    auto audioData = std::make_shared<Media::AVBuffer>();
    audioData->memory_ = std::make_shared<Media::AVSharedMemory>(1024, Media::AVSharedMemory::FLAGS_READ_WRITE);
    audioData->meta_ = std::make_shared<Media::Meta>();
    
    // 准备 codecMem 但 meta 为空
    OH_AVBuffer codecMem;
    codecMem.buffer_ = new OH_AVCodecBuffer();
    codecMem.buffer_->memory_ = std::make_shared<Media::AVSharedMemory>(1024, Media::AVSharedMemory::FLAGS_READ_WRITE);
    codecMem.buffer_->meta_ = nullptr;
    
    // 执行测试
    Status result = filter_->ProcessData(audioData, 1, &codecMem);
    
    // 验证结果
    EXPECT_EQ(result, Status::ERROR_NULL_POINTER);
    
    // 清理
    delete codecMem.buffer_;
    
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-end AudioDecoderFilter_ProcessData_010";

/**
 * @tc.number: AudioDecoderFilter_OnDecOutputBufferAvailable_001
 * @tc.name: AudioDecoderFilter::OnDecOutputBufferAvailable
 * @tc.desc: Verify normal output buffer processing
 */
HWTEST_F(AudioDecoderFilterTest, AudioDecoderFilter_OnDecOutputBufferAvailable_001, TestSize.Level1)
{
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-begin AudioDecoderFilter_OnDecOutputBufferAvailable_001";
    
    ASSERT_NE(filter_, nullptr);
    ASSERT_NE(mockProducer_, nullptr);
    
    // 设置解码器运行状态
    filter_->GetDecoderRunning().store(true);
    
    // 准备测试缓冲区
    auto buffer = new MockOH_AVBuffer();
    buffer->buffer_ = new MockAVBufferData();
    auto mockBufferData = static_cast<MockAVBufferData*>(buffer->buffer_);
    mockBufferData->memory_ = std::make_shared<MockAVBufferMemory>();
    mockBufferData->meta_ = std::make_shared<Media::Meta>();
    mockBufferData->pts_ = 12345;
    
    // 模拟内存大小
    EXPECT_CALL(*static_cast<MockAVBufferMemory*>(mockBufferData->memory_.get()), GetSize())
        .WillOnce(Return(1024));
    
    // 准备输出缓冲区
    auto outBuffer = std::make_shared<MockAVBuffer>();
    outBuffer->memory_ = std::make_shared<MockAVBufferMemory>();
    outBuffer->meta_ = std::make_shared<Media::Meta>();
    
    // 设置RequestBuffer期望
    EXPECT_CALL(*mockProducer_, RequestBuffer(_, _, _))
        .WillOnce(DoAll(SetArgReferee<0>(outBuffer), Return(Media::Status::OK)));
    
    // 设置PushBuffer期望
    EXPECT_CALL(*mockProducer_, PushBuffer(_, _))
        .WillOnce(Return(Media::Status::OK));
    
    // 设置内存写入期望
    EXPECT_CALL(*static_cast<MockAVBufferMemory*>(outBuffer->memory_.get()), Write(_, _, _))
        .WillOnce(Return());
    
    // 添加PTS到map
    filter_->GetPtsMap()[0] = 12345;
    
    // 调用被测方法
    filter_->OnDecOutputBufferAvailable(0, buffer);
    
    // 清理
    delete mockBufferData;
    delete buffer;
    
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-end AudioDecoderFilter_OnDecOutputBufferAvailable_001";
}

/**
 * @tc.number: AudioDecoderFilter_OnDecOutputBufferAvailable_002
 * @tc.name: AudioDecoderFilter::OnDecOutputBufferAvailable
 * @tc.desc: Verify behavior when decoder is not running
 */
HWTEST_F(AudioDecoderFilterTest, AudioDecoderFilter_OnDecOutputBufferAvailable_002, TestSize.Level1)
{
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-begin AudioDecoderFilter_OnDecOutputBufferAvailable_002";
    
    ASSERT_NE(filter_, nullptr);
    
    // 设置解码器未运行
    filter_->GetDecoderRunning().store(false);
    
    // 准备测试缓冲区
    auto buffer = new MockOH_AVBuffer();
    buffer->buffer_ = new MockAVBufferData();
    
    // 调用被测方法
    filter_->OnDecOutputBufferAvailable(0, buffer);
    
    // 验证没有任何生产者调用发生
    EXPECT_CALL(*mockProducer_, RequestBuffer(_, _, _))
        .Times(0);
    
    // 清理
    delete static_cast<MockAVBufferData*>(buffer->buffer_);
    delete buffer;
    
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-end AudioDecoderFilter_OnDecOutputBufferAvailable_002";
}

/**
 * @tc.number: AudioDecoderFilter_OnDecOutputBufferAvailable_003
 * @tc.name: AudioDecoderFilter::OnDecOutputBufferAvailable
 * @tc.desc: Verify behavior when buffer is null
 */
HWTEST_F(AudioDecoderFilterTest, AudioDecoderFilter_OnDecOutputBufferAvailable_003, TestSize.Level1)
{
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-begin AudioDecoderFilter_OnDecOutputBufferAvailable_003";
    
    ASSERT_NE(filter_, nullptr);
    
    // 设置解码器运行状态
    filter_->GetDecoderRunning().store(true);
    
    // 调用被测方法（传入null缓冲区）
    filter_->OnDecOutputBufferAvailable(0, nullptr);
    
    // 验证没有任何生产者调用发生
    EXPECT_CALL(*mockProducer_, RequestBuffer(_, _, _))
        .Times(0);
    
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-end AudioDecoderFilter_OnDecOutputBufferAvailable_003";
}

/**
 * @tc.number: AudioDecoderFilter_OnDecOutputBufferAvailable_004
 * @tc.name: AudioDecoderFilter::OnDecOutputBufferAvailable
 * @tc.desc: Verify behavior when output producer is null
 */
HWTEST_F(AudioDecoderFilterTest, AudioDecoderFilter_OnDecOutputBufferAvailable_004, TestSize.Level1)
{
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-begin AudioDecoderFilter_OnDecOutputBufferAvailable_004";
    
    ASSERT_NE(filter_, nullptr);
    
    // 设置解码器运行状态
    filter_->GetDecoderRunning().store(true);
    
    // 设置输出生产者为空
    filter_->GetOutputProducer() = nullptr;
    
    // 准备测试缓冲区
    auto buffer = new MockOH_AVBuffer();
    buffer->buffer_ = new MockAVBufferData();
    
    // 调用被测方法
    filter_->OnDecOutputBufferAvailable(0, buffer);
    
    // 清理
    delete static_cast<MockAVBufferData*>(buffer->buffer_);
    delete buffer;
    
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-end AudioDecoderFilter_OnDecOutputBufferAvailable_004";
}

/**
 * @tc.number: AudioDecoderFilter_OnDecOutputBufferAvailable_005
 * @tc.name: AudioDecoderFilter::OnDecOutputBufferAvailable
 * @tc.desc: Verify behavior when RequestBuffer fails
 */
HWTEST_F(AudioDecoderFilterTest, AudioDecoderFilter_OnDecOutputBufferAvailable_005, TestSize.Level1)
{
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-begin AudioDecoderFilter_OnDecOutputBufferAvailable_005";
    
    ASSERT_NE(filter_, nullptr);
    ASSERT_NE(mockProducer_, nullptr);
    
    // 设置解码器运行状态
    filter_->GetDecoderRunning().store(true);
    
    // 准备测试缓冲区
    auto buffer = new MockOH_AVBuffer();
    buffer->buffer_ = new MockAVBufferData();
    auto mockBuffer = static_cast<MockAVBufferData*>(buffer->buffer_);
    mockBuffer->memory_ = std::make_shared<MockAVBufferMemory>();
    mockBuffer->meta_ = std::make_shared<Media::Meta>();
    
    // 模拟内存大小
    EXPECT_CALL(*static_cast<MockAVBufferMemory*>(mockBuffer->memory_.get()), GetSize())
        .WillOnce(Return(1024));
    
    // 设置RequestBuffer失败
    EXPECT_CALL(*mockProducer_, RequestBuffer(_, _, _))
        .WillOnce(Return(Media::Status::ERROR_NO_MEMORY));
    
    // 设置PushBuffer不应该被调用
    EXPECT_CALL(*mockProducer_, PushBuffer(_, _))
        .Times(0);
    
    // 添加PTS到map
    filter_->GetPtsMap()[0] = 12345;
    
    // 调用被测方法
    filter_->OnDecOutputBufferAvailable(0, buffer);
    
    // 清理
    delete mockBuffer;
    delete buffer;
    
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-end AudioDecoderFilter_OnDecOutputBufferAvailable_005";
}

/**
 * @tc.number: AudioDecoderFilter_OnDecOutputBufferAvailable_006
 * @tc.name: AudioDecoderFilter::OnDecOutputBufferAvailable
 * @tc.desc: Verify behavior when output buffer meta is null
 */
HWTEST_F(AudioDecoderFilterTest, AudioDecoderFilter_OnDecOutputBufferAvailable_006, TestSize.Level1)
{
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-begin AudioDecoderFilter_OnDecOutputBufferAvailable_006";
    
    ASSERT_NE(filter_, nullptr);
    ASSERT_NE(mockProducer_, nullptr);
    
    // 设置解码器运行状态
    filter_->GetDecoderRunning().store(true);
    
    // 准备测试缓冲区
    auto buffer = new MockOH_AVBuffer();
    buffer->buffer_ = new MockAVBufferData();
    auto mockBuffer = static_cast<MockAVBufferData*>(buffer->buffer_);
    mockBuffer->memory_ = std::make_shared<MockAVBufferMemory>();
    mockBuffer->meta_ = std::make_shared<Media::Meta>();
    
    // 模拟内存大小
    EXPECT_CALL(*static_cast<MockAVBufferMemory*>(mockBuffer->memory_.get()), GetSize())
        .WillOnce(Return(1024));
    
    // 准备输出缓冲区（meta为null）
    auto outBuffer = std::make_shared<MockAVBuffer>();
    outBuffer->memory_ = std::make_shared<MockAVBufferMemory>();
    outBuffer->meta_ = nullptr;  // meta为空
    
    // 设置RequestBuffer期望
    EXPECT_CALL(*mockProducer_, RequestBuffer(_, _, _))
        .WillOnce(DoAll(SetArgReferee<0>(outBuffer), Return(Media::Status::OK)));
    
    // 设置PushBuffer期望（应该被调用一次）
    EXPECT_CALL(*mockProducer_, PushBuffer(_, _))
        .WillOnce(Return(Media::Status::OK));
    
    // 添加PTS到map
    filter_->GetPtsMap()[0] = 12345;
    
    // 调用被测方法
    filter_->OnDecOutputBufferAvailable(0, buffer);
    
    // 清理
    delete mockBuffer;
    delete buffer;
    
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-end AudioDecoderFilter_OnDecOutputBufferAvailable_006";
}

/**
 * @tc.number: AudioDecoderFilter_OnDecOutputBufferAvailable_007
 * @tc.name: AudioDecoderFilter::OnDecOutputBufferAvailable
 * @tc.desc: Verify behavior when buffer memory is null
 */
HWTEST_F(AudioDecoderFilterTest, AudioDecoderFilter_OnDecOutputBufferAvailable_007, TestSize.Level1)
{
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-begin AudioDecoderFilter_OnDecOutputBufferAvailable_007";
    
    ASSERT_NE(filter_, nullptr);
    
    // 设置解码器运行状态
    filter_->GetDecoderRunning().store(true);
    
    // 准备测试缓冲区（memory为空）
    auto buffer = new MockOH_AVBuffer();
    buffer->buffer_ = new MockAVBufferData();
    auto mockBuffer = static_cast<MockAVBufferData*>(buffer->buffer_);
    mockBuffer->memory_ = nullptr;
    mockBuffer->meta_ = std::make_shared<Media::Meta>();
    
    // 调用被测方法
    filter_->OnDecOutputBufferAvailable(0, buffer);
    
    // 验证没有任何生产者调用发生
    EXPECT_CALL(*mockProducer_, RequestBuffer(_, _, _))
        .Times(0);
    
    // 清理
    delete mockBuffer;
    delete buffer;
    
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-end AudioDecoderFilter_OnDecOutputBufferAvailable_007";
}

/**
 * @tc.number: AudioDecoderFilter_OnDecOutputBufferAvailable_008
 * @tc.name: AudioDecoderFilter::OnDecOutputBufferAvailable
 * @tc.desc: Verify behavior when buffer size is 0
 */
HWTEST_F(AudioDecoderFilterTest, AudioDecoderFilter_OnDecOutputBufferAvailable_008, TestSize.Level1)
{
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-begin AudioDecoderFilter_OnDecOutputBufferAvailable_008";
    
    ASSERT_NE(filter_, nullptr);
    
    // 设置解码器运行状态
    filter_->GetDecoderRunning().store(true);
    
    // 准备测试缓冲区（size为0）
    auto buffer = new MockOH_AVBuffer();
    buffer->buffer_ = new MockAVBufferData();
    auto mockBuffer = static_cast<MockAVBufferData*>(buffer->buffer_);
    mockBuffer->memory_ = std::make_shared<MockAVBufferMemory>();
    mockBuffer->meta_ = std::make_shared<Media::Meta>();
    
    // 模拟内存大小为0
    EXPECT_CALL(*static_cast<MockAVBufferMemory*>(mockBuffer->memory_.get()), GetSize())
        .WillOnce(Return(0));
    
    // 调用被测方法
    filter_->OnDecOutputBufferAvailable(0, buffer);
    
    // 验证没有任何生产者调用发生
    EXPECT_CALL(*mockProducer_, RequestBuffer(_, _, _))
        .Times(0);
    
    // 清理
    delete mockBuffer;
    delete buffer;
    
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-end AudioDecoderFilter_OnDecOutputBufferAvailable_008";
}

/**
 * @tc.number: AudioDecoderFilter_OnDecOutputBufferAvailable_009
 * @tc.name: AudioDecoderFilter::OnDecOutputBufferAvailable
 * @tc.desc: Verify behavior when frameOutIndex reaches INDEX_FLAG
 */
HWTEST_F(AudioDecoderFilterTest, AudioDecoderFilter_OnDecOutputBufferAvailable_009, TestSize.Level1)
{
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-begin AudioDecoderFilter_OnDecOutputBufferAvailable_009";
    
    ASSERT_NE(filter_, nullptr);
    ASSERT_NE(mockProducer_, nullptr);
    
    // 设置解码器运行状态
    filter_->GetDecoderRunning().store(true);
    
    // 设置frameOutIndex接近INDEX_FLAG
    filter_->GetFrameOutIndex() = 14;
    
    // 准备测试缓冲区
    auto buffer = new MockOH_AVBuffer();
    buffer->buffer_ = new MockAVBufferData();
    auto mockBuffer = static_cast<MockAVBufferData*>(buffer->buffer_);
    mockBuffer->memory_ = std::make_shared<MockAVBufferMemory>();
    mockBuffer->meta_ = std::make_shared<Media::Meta>();
    mockBuffer->pts_ = 12345;
    
    // 模拟内存大小
    EXPECT_CALL(*static_cast<MockAVBufferMemory*>(mockBuffer->memory_.get()), GetSize())
        .WillOnce(Return(1024));
    
    // 准备输出缓冲区
    auto outBuffer = std::make_shared<MockAVBuffer>();
    outBuffer->memory_ = std::make_shared<MockAVBufferMemory>();
    outBuffer->meta_ = std::make_shared<Media::Meta>();
    
    // 设置RequestBuffer期望
    EXPECT_CALL(*mockProducer_, RequestBuffer(_, _, _))
        .WillOnce(DoAll(SetArgReferee<0>(outBuffer), Return(Media::Status::OK)));
    
    // 设置PushBuffer期望
    EXPECT_CALL(*mockProducer_, PushBuffer(_, _))
        .WillOnce(Return(Media::Status::OK));
    
    // 设置内存写入期望
    EXPECT_CALL(*static_cast<MockAVBufferMemory*>(outBuffer->memory_.get()), Write(_, _, _))
        .WillOnce(Return());
    
    // 添加PTS到map（包括INDEX_FLAG）
    filter_->GetPtsMap()[14] = 12345;
    filter_->GetPtsMap()[15] = 67890;
    
    // 调用被测方法
    filter_->OnDecOutputBufferAvailable(0, buffer);
    
    // 验证frameOutIndex被重置
    EXPECT_EQ(filter_->GetFrameOutIndex(), 0);
    
    // 清理
    delete mockBuffer;
    delete buffer;
    
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-end AudioDecoderFilter_OnDecOutputBufferAvailable_009";
}

}

/**
 * @tc.number: AudioDecoderFilter_ProcessData_011
 * @tc.name: AudioDecoderFilter::ProcessData - Special frame index processing
 * @tc.desc: Verify special processing when frameInIndex_ reaches INDEX_FLAG
 */
HWTEST_F(AudioDecoderFilterTest, AudioDecoderFilter_ProcessData_011, TestSize.Level1)
{
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-begin AudioDecoderFilter_ProcessData_011";
    
    ASSERT_NE(filter_, nullptr);
    
    // 设置解码器运行状态
    filter_->GetDecoderRunning().store(true);
    filter_->GetAudioDecoder() = reinterpret_cast<OH_AVCodec*>(0x12345678);
    
    // 设置 frameInIndex_ 为 INDEX_FLAG - 1
    filter_->GetFrameInIndex() = 14; // INDEX_FLAG = 15
    
    // 准备有效的 audioData，包含 USER_FRAME_PTS
    auto audioData = std::make_shared<Media::AVBuffer>();
    audioData->memory_ = std::make_shared<Media::AVSharedMemory>(1024, Media::AVSharedMemory::FLAGS_READ_WRITE);
    audioData->meta_ = std::make_shared<Media::Meta>();
    audioData->meta_->SetData(Media::Tag::USER_FRAME_PTS, 5000);
    audioData->pts_ = 1000;
    
    OH_AVBuffer codecMem;
    codecMem.buffer_ = new OH_AVCodecBuffer();
    codecMem.buffer_->memory_ = std::make_shared<Media::AVSharedMemory>(1024, Media::AVSharedMemory::FLAGS_READ_WRITE);
    codecMem.buffer_->meta_ = std::make_shared<Media::Meta>();
    
    // 执行测试
    Status result = filter_->ProcessData(audioData, 1, &codecMem);
    
    // 验证结果
    EXPECT_EQ(result, Status::OK);
    EXPECT_EQ(filter_->GetFrameInIndex(), 0); // 应该被重置为0
    EXPECT_EQ(filter_->GetPtsMap()[15], 5000); // 特殊索引的PTS应该被设置
    EXPECT_EQ(filter_->GetPtsMap()[14], 1000); // 常规索引的PTS应该被设置
    
    // 清理
    delete codecMem.buffer_;
    
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-end AudioDecoderFilter_ProcessData_011";
}

/**
 * @tc.number: AudioDecoderFilter_ProcessData_012
 * @tc.name: AudioDecoderFilter::ProcessData - Large data size
 * @tc.desc: Verify processing with large data size
 */
HWTEST_F(AudioDecoderFilterTest, AudioDecoderFilter_ProcessData_012, TestSize.Level1)
{
    GTEST_LOG_(INFO) << "AudioDecoderFilterTest-begin AudioDecoderFilter_ProcessData_012";
    
    ASSERT_NE(filter_, nullptr);
    
    // 设置解码器运行状态
    filter_->GetDecoderRunning().store(true);
    filter_->GetAudioDecoder() = reinterpret_cast<OH_AVCodec*>(0x12345678);
    
    // 准备大的 audioData
    const size_t largeSize = 1024 * 1024; // 1MB
    auto audioData = std::make_shared<Media::AVBuffer>();
    audioData->memory_ = std::make_shared<Media::AVSharedMemory>(largeSize, Media